import radix
from cStringIO import StringIO
import os

path = os.path.abspath(os.path.dirname(__file__))
filename = path + '/PrefixToAS.map'

radix = radix.Radix()

doc_string = open(filename).read()
doc = StringIO(doc_string)
for line in doc:
	arr = line.split('|')
	node = radix.add(arr[1])
        node.data.update({'as':arr[2]})

def ip2as(ip):
	node = radix.search_best(ip)
        if node == None:
	       	return None
        return node.data['as']
